﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using ERP.Manager.DataEntity;
using ERP.Manager.BusinessServices;
using ERP.Manager.Controllers.CustomAttributes;
using System.IO;
namespace ERP.Manager.Controllers
{
    [CheckLoginAttribute]
    public class ECS_goodsController : Controller
    {
        private readonly ECS_goodsinfoService ecs_goodsinfoservice;
        private readonly ECS_categoryinfoService ecs_categoryinfoservice;
        private readonly ECS_brandinfoService ecs_brandinfoservice;
        private readonly ECS_goods_typeinfoService ecs_goods_typeinfoservice;
        private readonly ECS_attributeinfoService ecs_attributeinfoservice;
        private readonly ECS_goods_attrinfoService ecs_goods_attrinfoservice;
        public ECS_goodsController() { }
        public ECS_goodsController(ECS_goodsinfoService ecs_goodsinfoservice, ECS_categoryinfoService ecs_categoryinfoservice, ECS_brandinfoService ecs_brandinfoservice, ECS_goods_typeinfoService ecs_goods_typeinfoservice, ECS_attributeinfoService ecs_attributeinfoservice, ECS_goods_attrinfoService ecs_goods_attrinfoservice)
        {
            this.ecs_goodsinfoservice = ecs_goodsinfoservice;
            this.ecs_categoryinfoservice = ecs_categoryinfoservice;
            this.ecs_brandinfoservice = ecs_brandinfoservice;
            this.ecs_goods_typeinfoservice = ecs_goods_typeinfoservice;
            this.ecs_attributeinfoservice = ecs_attributeinfoservice;
            this.ecs_goods_attrinfoservice = ecs_goods_attrinfoservice;
        }

        #region 商品信息页面
        public ActionResult ShowECS_goods(int? page, string cat_id)
        {
            int pagecount = page ?? 1;
            List<ECS_goodsinfo> ecs_goods = null;
            if (cat_id != null)
            {
                ecs_goods = ecs_goodsinfoservice.all_ecs_goodsinfo_category_cat_id_page(pagecount, int.Parse(cat_id.ToString()));
                ViewData["ecs_goods"] = ecs_goods;
                int pagesize = ecs_goodsinfoservice.all_ecs_goodsinfo_category_cat_id_page_count(int.Parse(cat_id.ToString()));
                ViewData["ecs_goods_pagesize"] = pagesize;
            }
            else
            {
                ecs_goods = ecs_goodsinfoservice.all_ecs_goodsinfo_page(pagecount);
                ViewData["ecs_goods"] = ecs_goods;
                int pagesize = ecs_goodsinfoservice.all_ecs_goodsinfo_page_count();
                ViewData["ecs_goods_pagesize"] = pagesize;
            }
            return View();
        }
        #endregion

        #region 添加商品页面
        public ActionResult AddECS_goods()
        {
            List<ECS_categoryinfo> ecs_category = ecs_categoryinfoservice.all_ecs_categroyinfo();
            ViewData["ecs_category"] = ecs_category;
            List<ECS_brandinfo> ecs_brand = ecs_brandinfoservice.all_ecs_brandinfo();
            ViewData["ecs_brand"] = ecs_brand;
            List<ECS_goods_typeinfo> ecs_goods_type = ecs_goods_typeinfoservice.all_ecs_goods_typeinfo();
            ViewData["ecs_goods_type"] = ecs_goods_type;
            return View();
        }
        #endregion

        #region 提交 添加商品页面
        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateInput(false)]
        public void AddECS_goods(FormCollection FormValue)
        {
            try
            {
                ECS_goodsinfo goods = new ECS_goodsinfo();
                goods.ecs_categoryinfo.cat_id = int.Parse(FormValue["cat_id"]);
                goods.goods_sn = FormValue["goods_sn"] == "" ? RandNum() : FormValue["goods_sn"];
                goods.goods_name = FormValue["goods_name"];
                goods.ecs_brandinfo.brand_id = int.Parse(FormValue["brand_id"]);
                goods.goods_number = FormValue["goods_number"] == null ? 0 : int.Parse(FormValue["goods_number"]);
                goods.market_price = FormValue["market_price"] == "" ? decimal.Parse((0.00).ToString()) : decimal.Parse(FormValue["market_price"]);
                goods.warn_number = FormValue["warn_number"] == null ? 0 : int.Parse(FormValue["warn_number"]);
                goods.keywords = FormValue["keywords"] == "" ? "" : FormValue["keywords"];
                goods.goods_brief = FormValue["goods_brief"] == "" ? "" : FormValue["goods_brief"];
                goods.goods_desc = FormValue["goods_desc"];
                //文件上传
                foreach (string file in Request.Files)
                {
                    var fileBase = Request.Files[file];
                    if (fileBase.ContentLength > 0)//获取文件上传的大小
                    {
                        string fileName = fileBase.FileName;
                        fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                        goods.goods_img = fileName;
                        string filePath = Server.MapPath(@"~/Content/ECShopImages/" + fileName);
                        fileBase.SaveAs(filePath);
                    }
                    else
                    {
                        goods.goods_img = "";
                    }
                }
                goods.is_on_sale = FormValue["is_on_sale"] == null ? 0 : 1;
                goods.is_alone_sale = FormValue["is_alone_sale"] == null ? 0 : 1;
                goods.add_time = DateTime.Now.AddDays(0);
                goods.is_best = FormValue["is_best"] == null ? 0 : 1;
                goods.is_new = FormValue["is_new"] == null ? 0 : 1;
                goods.is_hot = FormValue["is_hot"] == null ? 0 : 1;
                goods.ecs_goods_typeinfo.cat_id = int.Parse(FormValue["goods_type"]);
                goods.seller_note = FormValue["seller_note"];
                int rowcount = ecs_goodsinfoservice.add_ecs_goods(goods);
                if (rowcount > 0)
                {
                    Response.Write("<script>javascript:alert('您添加商品成功！');window.location.href='/ECS_goods/AddECS_goods';</script>");
                }
                else
                {
                    Response.Write("<script>javascript:alert('您添加商品失败！');window.location.href='/ECS_goods/AddECS_goods';</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>javascript:alert('" + ex.Message + "');window.location.href='/ECS_goods/AddECS_goods';</script>");
            }
        }
        #endregion

        #region 修改商品页面
        public ActionResult UpdateECS_goods(string goods_id)
        {
            List<ECS_categoryinfo> ecs_category = ecs_categoryinfoservice.all_ecs_categroyinfo();
            ViewData["ecs_category"] = ecs_category;
            List<ECS_brandinfo> ecs_brand = ecs_brandinfoservice.all_ecs_brandinfo();
            ViewData["ecs_brand"] = ecs_brand;
            List<ECS_goods_typeinfo> ecs_goods_type = ecs_goods_typeinfoservice.all_ecs_goods_typeinfo();
            ViewData["ecs_goods_type"] = ecs_goods_type;
            ECS_goodsinfo goods = ecs_goodsinfoservice.detail_ecs_goods(int.Parse(goods_id));
            ViewData["ecs_goods"] = goods;
            return View();
        }
        #endregion

        #region 提交 修改商品页面
        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateInput(false)]
        public void UpdateECS_goods(FormCollection FormValue)
        {
            try
            {
                ECS_goodsinfo goods = new ECS_goodsinfo();
                goods.goods_id = int.Parse(FormValue["goods_id"]);
                goods.ecs_categoryinfo.cat_id = int.Parse(FormValue["cat_id"]);
                goods.goods_sn = FormValue["goods_sn"] == "" ? RandNum() : FormValue["goods_sn"];
                goods.goods_name = FormValue["goods_name"];
                goods.ecs_brandinfo.brand_id = int.Parse(FormValue["brand_id"]);
                goods.goods_number = FormValue["goods_number"] == null ? 0 : int.Parse(FormValue["goods_number"]);
                goods.market_price = FormValue["market_price"] == "" ? decimal.Parse((0.00).ToString()) : decimal.Parse(FormValue["market_price"]);
                goods.warn_number = FormValue["warn_number"] == null ? 0 : int.Parse(FormValue["warn_number"]);
                goods.keywords = FormValue["keywords"] == "" ? "" : FormValue["keywords"];
                goods.goods_brief = FormValue["goods_brief"] == "" ? "" : FormValue["goods_brief"];
                goods.goods_desc = FormValue["goods_desc"];
                //文件上传
                foreach (string file in Request.Files)
                {
                    var fileBase = Request.Files[file];
                    if (fileBase.ContentLength > 0)//获取文件上传的大小
                    {
                        string fileName = fileBase.FileName;
                        fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                        goods.goods_img = fileName;
                        string filePath = Server.MapPath(@"~/Content/ECShopImages/" + fileName);
                        fileBase.SaveAs(filePath);
                    }
                    else
                    {
                        ECS_goodsinfo ecs_goodsinfo = ecs_goodsinfoservice.detail_ecs_goods(int.Parse(FormValue["goods_id"]));
                        goods.goods_img = ecs_goodsinfo.goods_img;
                    }
                }
                goods.is_on_sale = FormValue["is_on_sale"] == null ? 0 : 1;
                goods.is_alone_sale = FormValue["is_alone_sale"] == null ? 0 : 1;
                goods.is_best = FormValue["is_best"] == null ? 0 : 1;
                goods.is_new = FormValue["is_new"] == null ? 0 : 1;
                goods.is_hot = FormValue["is_hot"] == null ? 0 : 1;
                goods.ecs_goods_typeinfo.cat_id = int.Parse(FormValue["goods_type"]);
                goods.seller_note = FormValue["seller_note"];
                int rowcount = ecs_goodsinfoservice.update_ecs_goods(goods);
                if (rowcount > 0)
                {
                    Response.Write("<script>javascript:alert('您修改商品成功！');window.location.href='/ECS_goods/ShowECS_goods';</script>");
                }
                else
                {
                    Response.Write("<script>javascript:alert('您修改商品失败！');window.location.href='/ECS_goods/ShowECS_goods';</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>javascript:alert(" + ex.Message + ");window.location.href='/ECS_goods/ShowECS_goods';</script>");
            }
        }
        #endregion

        #region 复制添加商品商品
        public ActionResult CopyAddECS_goods(string goods_id)
        {
            List<ECS_categoryinfo> ecs_category = ecs_categoryinfoservice.all_ecs_categroyinfo();
            ViewData["ecs_category"] = ecs_category;
            List<ECS_brandinfo> ecs_brand = ecs_brandinfoservice.all_ecs_brandinfo();
            ViewData["ecs_brand"] = ecs_brand;
            List<ECS_goods_typeinfo> ecs_goods_type = ecs_goods_typeinfoservice.all_ecs_goods_typeinfo();
            ViewData["ecs_goods_type"] = ecs_goods_type;
            ECS_goodsinfo goods = ecs_goodsinfoservice.detail_ecs_goods(int.Parse(goods_id));
            ViewData["ecs_goods"] = goods;
            return View();
        }
        #endregion

        #region 提交 复制添加商品商品
        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateInput(false)]
        public void CopyAddECS_goods(FormCollection FormValue)
        {
            try
            {
                ECS_goodsinfo goods = new ECS_goodsinfo();
                goods.ecs_categoryinfo.cat_id = int.Parse(FormValue["cat_id"]);
                goods.goods_sn = FormValue["goods_sn"] == "" ? RandNum() : FormValue["goods_sn"];
                goods.goods_name = FormValue["goods_name"];
                goods.ecs_brandinfo.brand_id = int.Parse(FormValue["brand_id"]);
                goods.goods_number = FormValue["goods_number"] == null ? 0 : int.Parse(FormValue["goods_number"]);
                goods.market_price = FormValue["market_price"] == "" ? decimal.Parse((0.00).ToString()) : decimal.Parse(FormValue["market_price"]);
                goods.warn_number = FormValue["warn_number"] == null ? 0 : int.Parse(FormValue["warn_number"]);
                goods.keywords = FormValue["keywords"] == "" ? "" : FormValue["keywords"];
                goods.goods_brief = FormValue["goods_brief"] == "" ? "" : FormValue["goods_brief"];
                goods.goods_desc = FormValue["goods_desc"];
                //文件上传
                foreach (string file in Request.Files)
                {
                    var fileBase = Request.Files[file];
                    if (fileBase.ContentLength > 0)//获取文件上传的大小
                    {
                        string fileName = fileBase.FileName;
                        fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                        goods.goods_img = fileName;
                        string filePath = Server.MapPath(@"~/Content/ECShopImages/" + fileName);
                        fileBase.SaveAs(filePath);
                    }
                    else
                    {
                        goods.goods_img = FormValue["copy_goods_img"] == "" ? "" : FormValue["copy_goods_img"];
                    }
                }
                goods.is_on_sale = FormValue["is_on_sale"] == null ? 0 : 1;
                goods.is_alone_sale = FormValue["is_alone_sale"] == null ? 0 : 1;
                goods.add_time = DateTime.Now.AddDays(0);
                goods.is_best = FormValue["is_best"] == null ? 0 : 1;
                goods.is_new = FormValue["is_new"] == null ? 0 : 1;
                goods.is_hot = FormValue["is_hot"] == null ? 0 : 1;
                goods.ecs_goods_typeinfo.cat_id = int.Parse(FormValue["goods_type"]);
                goods.seller_note = FormValue["seller_note"];
                int rowcount = ecs_goodsinfoservice.add_ecs_goods(goods);
                if (rowcount > 0)
                {
                    Response.Write("<script>javascript:alert('复制商品成功！');window.location.href='/ECS_goods/ShowECS_goods';</script>");
                }
                else
                {
                    Response.Write("<script>javascript:alert('复制商品失败！');window.location.href='/ECS_goods/ShowECS_goods';</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>javascript:alert(" + ex.Message + ");window.location.href='/ECS_goods/ShowECS_goods';</script>");
            }
        }
        #endregion

        #region 根据编号把商品放入到商品回收站当中
        public string AjaxDeleteECS_goods(string goods_id)
        {
            try
            {
                int rowcount = ecs_goodsinfoservice.delete_ecs_goods(int.Parse(goods_id.ToString()));
                if (rowcount > 0)
                {
                    return "success";
                }
                else
                {
                    return "error";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        #endregion

        #region 产生商品的随机货号
        private string RandNum()
        {
            string goodssn = "";
            Random rand = new Random();
            goodssn = "ECS" + rand.Next(100000, 999999).ToString();

            List<ECS_goodsinfo> list = ecs_goodsinfoservice.all_ecs_goodsinfo();
            List<string> goods_sn = new List<string>();
            foreach (var item in list)
            {
                goods_sn.Add(item.goods_sn);
            }
            if (!goods_sn.Contains(goodssn))
            {
                return goodssn;
            }
            else
            {
                goodssn = RandNum();
            }
            return goodssn;
        }
        #endregion

        #region 商品回收站页面
        public ActionResult ShowECS_goods_remove(int? page)
        {
            int pagecount = page ?? 1;
            List<ECS_goodsinfo> list = ecs_goodsinfoservice.all_ecs_goodsinfo_remove_page(pagecount);
            ViewData["ecs_goods"] = list;
            int pagesize = ecs_goodsinfoservice.all_ecs_goodsinfo_remove_page_count();
            ViewData["ecs_goods_pagesize"] = pagesize;
            return View();
        }
        #endregion

        #region 修改商品为还原为正式商品
        public string Ajaxupdate_ecs_goodsinfo_remove(string goods_id)
        {
            try
            {
                int rowcount = ecs_goodsinfoservice.update_ecs_goodsinfo_remove(int.Parse(goods_id.ToString()));
                if (rowcount > 0)
                {
                    return "success";
                }
                else
                {
                    return "error";
                }
            }
            catch (Exception)
            {
                return "error";
            }
        }
        #endregion

        #region 删除回收站当中的商品信息
        public string Ajaxremovedelete_ecs_goods_remove(string goods_id)
        {
            try
            {
                int rowcountone = 0;
                List<ECS_goods_attrinfo> list = ecs_goods_attrinfoservice.all_ecs_goods_attrinfo(int.Parse(goods_id));
                if (list.Count > 0)
                {
                    int rowcount = ecs_goods_attrinfoservice.delete_ecs_goods_attrinfo(int.Parse(goods_id));
                    rowcountone = ecs_goodsinfoservice.delete_ecs_goods_remove(int.Parse(goods_id.ToString()));
                    if (rowcount > 0 || rowcountone > 0)
                    {
                        return "success";
                    }
                    else
                    {
                        return "error";
                    }
                }
                rowcountone = ecs_goodsinfoservice.delete_ecs_goods_remove(int.Parse(goods_id.ToString()));
                if (rowcountone > 0)
                {
                    return "success";
                }
                else
                {
                    return "error";
                }

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        #endregion

        #region 批量修改商品为还原为正式商品
        public string ALLAjaxupdate_ecs_goodsinfo_remove(string ALL_goods_id)
        {
            try
            {
                int rowcount = 0;
                string[] goods_id = ALL_goods_id.Split(',');
                for (int i = 0; i < goods_id.Length - 1; i++)
                {
                    rowcount = ecs_goodsinfoservice.update_ecs_goodsinfo_remove(int.Parse(goods_id[i]));
                }
                if (rowcount > 0)
                {
                    return "success";
                }
                else
                {
                    return "error";
                }
            }
            catch (Exception)
            {
                return "error";
            }
        }
        #endregion

        #region 批量删除回收站当中的商品信息
        public string ALLAjaxremovedelete_ecs_goods_remove(string ALL_goods_id)
        {
            try
            {
                int rowcount = 0;
                string[] goods_id = ALL_goods_id.Split(',');
                for (int i = 0; i < goods_id.Length - 1; i++)
                {
                    List<ECS_goods_attrinfo> list = ecs_goods_attrinfoservice.all_ecs_goods_attrinfo(int.Parse(goods_id[i]));
                    if (list.Count>0)
                    {
                          rowcount = ecs_goods_attrinfoservice.delete_ecs_goods_attrinfo(int.Parse(goods_id[i]));
                    }
                    rowcount = ecs_goodsinfoservice.delete_ecs_goods_remove(int.Parse(goods_id[i]));
                }
                if (rowcount > 0)
                {
                    return "success";
                }
                else
                {
                    return "error";
                }
            }
            catch (Exception)
            {
                return "error";
            }
        }
        #endregion

        #region 根据商品类型编号去查询商品类型下面的商品属性
        public JsonResult Ajaxgoods_type_cat_id_showecs_attributeinfo(int goodsType)
        {
            List<ECS_attributeinfo> list = ecs_attributeinfoservice.all_ecs_attributeinfo_page(goodsType, 1);
            return Json(list);
        }
        #endregion

        #region 根据商品类型属性编号查询商品类型属性的可选值列表
        public string Ajaxecs_attributeinfo_showattr_values(int attr_id)
        {
            string html = "";
            try
            {
                ECS_attributeinfo ecs_attribute = ecs_attributeinfoservice.detail_ecs_attributeinfo(attr_id);
                string[] attr_values = ecs_attribute.attr_values.Split('\n');
                for (int i = 0; i < attr_values.Length; i++)
                {
                    html += "<option value=" + attr_values[i] + ">" + attr_values[i] + "</option>";
                }
                return html;
            }
            catch (Exception)
            {

                return html;
            }
        }
        #endregion

        #region Ajax请求商品品牌的方法
        public JsonResult Ajaxecs_brand_info()
        {
            List<ECS_brandinfo> list = ecs_brandinfoservice.all_ecs_brandinfo();
            return Json(list);
        }
        #endregion

        #region Ajax请求得到搜索出的数据
        public string Ajaxecs_goods_info(int? page, int brand_id, string goods_name, string begintime, string end_time)
        {
            int pagecount = page ?? 1;
            List<ECS_goodsinfo> list = null;
            string html = "";
            list = ecs_goodsinfoservice.search_all_ecs_goodsinfo_page(pagecount, brand_id, goods_name, begintime, end_time);
            if (list.Count == 0)
            {
                html += "<table id=\"Tableuserinfo\" border=\"1px\" width=\"100%\" cellpadding=\"0px\" cellspacing=\"0px\" style=\"border-left: 0px; border-right: 0px;\">";
                html += "<tr style=\"height: 22px;\">";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">商品货号</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');border: 0px;\">商品名称</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">商品类型</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">商品属性</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">添加时间</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');border: 0px;\">商品价格</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');  border: 0px;\">库存数量</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">操作</td>";
                html += "</tr>";
                html += "<tr onmouseover=\"onTrover(this);\" onmouseout=\"onTrout(this);\"><td colspan=\"8\" align=\"center\" style=\"height: 30px;\"><font color=\"red\">未搜索到相关的商品信息！！！</font></td></tr>";
                html += "</table>";
            }
            else
            {
                html += "<table id=\"Tableuserinfo\" border=\"1px\" width=\"100%\" cellpadding=\"0px\" cellspacing=\"0px\" style=\"border-left: 0px; border-right: 0px;\">";
                html += "<tr style=\"height: 22px;\">";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');border: 0px;\">商品货号</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');border: 0px;\">商品名称</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">商品类型</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">商品属性</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">添加时间</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');border: 0px;\">商品价格</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif');  border: 0px;\">库存数量</td>";
                html += "<td style=\"background-image: url('../../Content/ModeImages/bg2.gif'); border: 0px;\">操作</td>";
                html += "</tr>";
                foreach (var item in list)
                {
                    html += "<tr style=\"height: 25px;\" onmouseover=\"onTrover(this);\" onmouseout=\"onTrout(this);\">";
                    html += "<td><input type=\"hidden\" id=\"new_goods_id\" value=" + item.goods_id + " />" + item.goods_sn + "</td>";
                    html += "<td>" + item.goods_name + "</td>";
                    html += "<td>" + item.ecs_goods_typeinfo.cat_name + "</td>";
                    html += "<td title=" + item.attr_value + ">";
                    if (item.attr_value == "")
                    {
                        html += "<font color=\"red\">还没属性请</font>&nbsp;<a onclick=\"javascript:window.location.href='/ECS_goods_attr/AddECS_goods_attr?goods_id=" + item.goods_id + "&goods_type_id=" + item.ecs_goods_typeinfo.cat_id + "'\">添 加</a> ";
                    }
                    else
                    {
                        html += "" + item.attr_value + "&nbsp;&nbsp;&nbsp;&nbsp;<a onclick=\"javascript:window.location.href='/ECS_goods_attr/UpdateECS_goods_attr?goods_id=" + item.goods_id + "&goods_type_id=" + item.ecs_goods_typeinfo.cat_id + "'\">修 改</a>";
                    }
                    html += "</td>";
                    html += "<td>" + item.add_time.ToString("yyyy-MM-dd HH:mm") + "</td>";
                    html += "<td><font face=\"华文新魏\" color=\"red\">￥" + item.market_price + "元</font></td>";
                    html += "<td>" + item.goods_number + "</td>";
                    html += "<td style=\"width: 10%;\">";
                    html += "<a onclick=\"javascript:window.location.href='/ECS_goods/ECS_goods_Detail?goods_id=" + item.goods_id + "'\" title=\"详细信息\">详细信息</a>&nbsp;";
                    html += "<a onclick=\"javascript:window.location.href='/ECS_goods/UpdateECS_goods?goods_id=" + item.goods_id + "'\" title=\"修改商品\"><img alt=\"修改商品\" src=\"../../Content/IndexImages/edt.gif\" width=\"12px\" height=\"12px\" style=\"border: 0px;\" /></a>&nbsp;";
                    html += "<a onclick=\"javascript:window.location.href='/ECS_goods/CopyAddECS_goods?goods_id=" + item.goods_id + "'\" title=\"复制商品\"><img alt=\"修改\" src=\"../../Content/IndexImages/icon_copy.gif\" width=\"12px\" height=\"12px\" style=\"border: 0px;\" /></a>&nbsp;";
                    html += "<a title=\"放入回收站\" onclick=\"AjaxdeleteECS_goods(" + item.goods_id + ");\"> <img alt=\"放入回收站\" src=\"../../Content/IndexImages/icon_trash.gif\" width=\"12px\" height=\"12px\" style=\"border: 0px;\" /></a>";
                    html += "</td>";
                    html += "</tr>";
                }
                html += "</table>";
                //得到所有数据的总数；
                int count = ecs_goodsinfoservice.search_all_ecs_goodsinfo_page_count(brand_id, goods_name, begintime, end_time);
                //获得总页码数
                int pagesize = (int)Math.Ceiling(count / (double)11);
                html += "<br /><table border='0px'><tr>";
                if (pagecount == 1)
                {
                    html += "<td>总共有:&nbsp;<font color='red'>" + count + "</font>&nbsp;条数据&nbsp;&nbsp;</td><td>当前第" + pagecount + "/" + pagesize + "页";
                    html += "&nbsp;&nbsp;&nbsp;<a onclick='javascript:'>首页</a>&nbsp;&nbsp;<a onclick='javascript:'>上一页</a>";
                }
                else
                {
                    html += "<td>总共有:&nbsp;<font color='red'>" + count + "</font>&nbsp;条数据&nbsp;&nbsp;</td><td>当前第" + pagecount + "/" + pagesize + "页";
                    html += "&nbsp;&nbsp;&nbsp;<a onclick='javascript:searchgoods_name(" + 1 + ")'>首页</a>&nbsp;&nbsp;<a onclick='javascript:searchgoods_name(" + (pagecount - 1) + ");'>上一页</a>";
                }
                if (pagecount == pagesize)
                {
                    html += "&nbsp;&nbsp;<a onclick='javascript:'>下一页</a>&nbsp;&nbsp;";
                    html += "<a onclick='javascript:'>尾页</a></td>";
                }
                else
                {
                    html += "&nbsp;&nbsp;<a onclick='javascript:searchgoods_name(" + (pagecount + 1) + ");'>下一页</a>&nbsp;&nbsp;";
                    html += "<a onclick='javascript:searchgoods_name(" + pagesize + ");'>尾页</a></td>";
                }
                html += "</tr>";
                html += "</table>";
            }
            return html;
        }
        #endregion

        #region 商品详细页面
        public ActionResult ECS_goods_Detail(int goods_id)
        {
            ECS_goodsinfo ecs_goodsinfo = ecs_goodsinfoservice.detail_ecs_goods(goods_id);
            ViewData["ecs_goodsinfo"] = ecs_goodsinfo;
            ECS_brandinfo ecs_brandinfo = ecs_brandinfoservice.detail_ecs_brandinfo(ecs_goodsinfo.ecs_brandinfo.brand_id);
            ViewData["ecs_brandinfo"] = ecs_brandinfo;
            List<ECS_goods_attrinfo> ecs_goods_attrinfo = ecs_goods_attrinfoservice.all_ecs_goods_attrinfo(goods_id);
            ViewData["ecs_goods_attrinfo"] = ecs_goods_attrinfo;
            return View();
        }
        #endregion
    }
}
